#include <iostream>

class Color
{
public:
    //绘画的纯虚函数
    virtual void paint(const std::string & pentype, const std::string & name) = 0;
};
/* 颜色单独抽离与Color类 */
class Red : public Color
{
public:
    void paint(const std::string & pentype, const std::string & name)
    {
        std::cout<<" 用"<<pentype<<"画红色的"<<name<<std::endl;
    }

};

class Blue : public Color
{
public:
    void paint(const std::string & pentype, const std::string & name)
    {
        std::cout<<" 用"<<pentype<<"画蓝色的"<<name<<std::endl;
    }

};

class Pen
{
public:
    virtual void Draw(const std::string & name) = 0;
    void SetColor(Color * c)
    {
        this->c = c;
    }
protected:
    Color *c;       //颜色组合于笔的类型
};

class Pencil : public Pen
{
public:
    void Draw(const std::string & name)
    {
        c->paint("铅笔", name);
    }

};

class SmallPen : public Pen
{
public:
    void Draw(const std::string & name)
    {
        c->paint("毛笔", name);
    }

};


int main()
{
    Color *c1 = new Red;
    Color *c2 = new Blue;

    Pen *p1 = new Pencil;
    Pen *p2 = new SmallPen;
//笔和颜色随意组合
    p1->SetColor(c1);
    p1->Draw("太阳");   //输出 用铅笔画红色的太阳

    p2->SetColor(c2);
    p2->Draw("大海");   //输出 用毛笔画蓝色的大海
    return 0;
}